Get OSM data

osmdata uses the overpass API to download
London

london <- opq(bbox = 'greater london uk') %>%
  add_osm_feature(key = 'highway', value = 'footway') %>%
  osmdata_sf()
print(london)
## Object of class 'osmdata' with:
##                  $bbox : 51.2867601,-0.5103751,51.6918741,0.3340155
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 494180 points
##             $osm_lines : 'sf' Simple Features Collection with 108874 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 2247 polygons
##        $osm_multilines : 'sf' Simple Features Collection with 3 multilinestrings
##     $osm_multipolygons : 'sf' Simple Features Collection with 79 multipolygons
lon_lines <- london[["osm_lines"]]
b_lon <- lon_lines %>%
  st_bbox() %>%
  st_as_sfc() %>%
  st_centroid() %>%
  st_transform(crs=3857) %>%
  st_buffer(5000) %>% # buffered distance from centroid
  st_bbox() %>% 
  st_as_sfc() %>%
  st_transform(crs=4326)
## Warning in st_centroid.sfc(.): st_centroid does not give correct centroids for
## longitude/latitude data
p_lon1 <- lon_lines %>%
  st_crop(., b_lon) %>%
  ggplot() +
  geom_sf(colour="tomato") +
  theme_tufte() +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank()) +
   ggtitle('London')
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
p_lon1

Barcelona

barce <- opq(bbox = 'barcelona spain') %>%
  add_osm_feature(key = 'highway', value = 'footway') %>%
  osmdata_sf()
print(barce)
## Object of class 'osmdata' with:
##                  $bbox : 41.3170353,2.0524977,41.4679135,2.2283555
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 133020 points
##             $osm_lines : 'sf' Simple Features Collection with 41972 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 162 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 7 multipolygons
bar_lines <- barce[["osm_lines"]]
b_bar <- bar_lines %>%
  st_bbox() %>%
  st_as_sfc() %>%
  st_centroid() %>%
  st_transform(crs=3857) %>%
  st_buffer(5000) %>% # buffered distance from centroid
  st_bbox() %>% 
  st_as_sfc() %>%
  st_transform(crs=4326)
## Warning in st_centroid.sfc(.): st_centroid does not give correct centroids for
## longitude/latitude data
p_bar1 <- bar_lines %>%
  st_crop(., b_bar) %>%
  ggplot() +
  geom_sf(colour="tomato") +
  theme_tufte() +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank()) +
   ggtitle('Barcelona')
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
p_bar1

Paris

paris <- opq(bbox = 'paris france') %>%
  add_osm_feature(key = 'highway', value = 'footway') %>%
  osmdata_sf()
print(paris)
## Object of class 'osmdata' with:
##                  $bbox : 48.6966969,2.1914616,49.0166969,2.5114616
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 306248 points
##             $osm_lines : 'sf' Simple Features Collection with 56844 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 3317 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 256 multipolygons
par_lines <- paris[["osm_lines"]]
b_par <- par_lines %>%
  st_bbox() %>%
  st_as_sfc() %>%
  st_centroid() %>%
  st_transform(crs=3857) %>%
  st_buffer(5000) %>% # buffered distance from centroid
  st_bbox() %>% 
  st_as_sfc() %>%
  st_transform(crs=4326)
## Warning in st_centroid.sfc(.): st_centroid does not give correct centroids for
## longitude/latitude data
p_par1 <- par_lines %>%
  st_crop(., b_par) %>%
  ggplot() +
  geom_sf(colour="tomato") +
  theme_tufte() +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank()) +
   ggtitle('Paris')
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
p_par1

New York

ny <- opq(bbox = 'new york usa') %>%
  add_osm_feature(key = 'highway', value = 'footway') %>%
  osmdata_sf()
print(ny)
## Object of class 'osmdata' with:
##                  $bbox : 40.477399,-74.25909,40.9161785,-73.7001809
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 359742 points
##             $osm_lines : 'sf' Simple Features Collection with 97091 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 4506 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 6 multipolygons
ny_lines <- ny[["osm_lines"]]
b_ny <- ny_lines %>%
  st_bbox() %>%
  st_as_sfc() %>%
  st_centroid() %>%
  st_transform(crs=3857) %>%
  st_buffer(5000) %>% # buffered distance from centroid
  st_bbox() %>% 
  st_as_sfc() %>%
  st_transform(crs=4326)
## Warning in st_centroid.sfc(.): st_centroid does not give correct centroids for
## longitude/latitude data
p_ny1 <- ny_lines %>%
  st_crop(., b_ny) %>%
  ggplot() +
  geom_sf(colour="tomato") +
  theme_tufte() +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank()) +
   ggtitle('New York')
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
p_ny1

(p_lon1 + p_bar1) / (p_par1 + p_ny1)